<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.zy.entity.Order" %>
<html>

<body>
    <table class="order-table">
        <thead>
            <tr>
                <th>订单ID</th>
                <th>支付金额</th>
                <th>支付时间</th>
                <th>购物心得</th>
            </tr>
        </thead>
        <tbody>
            <% 
                // 从请求中获取订单列表
                List<Order> orders = (List<Order>) request.getAttribute("orders"); 
            %>
            <% if (orders != null) { %>
                <% for (Order order : orders) { %>
                    <tr>
                        <td><%= order.getId() %></td>
                        <td>¥<%= order.getPaymentAmount() %></td>
                        <td><%= order.getPaymentTime() %></td>
                        <td>
                            <button class="review-btn" data-order-id="<%= order.getId() %>">开始评价</button>
                        </td>
                    </tr>
                <% } %>
            <% } else { %>
                <tr>
                    <td colspan="4">没有订单记录</td>
                </tr>
            <% } %>
        </tbody>
    </table>
    <div id="reviewModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <h2>添加评价</h2>
            <textarea id="reviewContent" placeholder="请输入您的评价"></textarea>
            <button id="submitReview">提交评价</button>
        </div>
    </div>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f0f2f5;
            margin: 0;
            padding: 0;
        }

        .order-table {
            width: 80%;
            margin: 50px auto;
            border-collapse: collapse;
            background-color: #fff;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
            overflow: hidden;
        }

        .order-table th,
        .order-table td {
            padding: 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        .order-table th {
            background-color: #3f51b5;
            color: white;
        }

        .order-table tr:hover {
            background-color: #f1f1f1;
        }

        .review-btn {
            background-color: #1e88e5;
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .review-btn:hover {
            background-color: #1565c0;
        }

        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgb(0,0,0);
            background-color: rgba(0,0,0,0.4);
        }

        .modal-content {
            background-color: #fefefe;
            margin: 15% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 80%;
            max-width: 500px;
            border-radius: 8px;
        }

        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
        }

        .close:hover,
        .close:focus {
            color: black;
            text-decoration: none;
            cursor: pointer;
        }

        #reviewContent {
            width: 100%;
            height: 100px;
            margin-top: 10px;
            margin-bottom: 10px;
        }

        #submitReview {
            background-color: #1e88e5;
            color: white;
            border: none;
            padding: 10px 15px;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        #submitReview:hover {
            background-color: #1565c0;
        }
    </style>
    <script>
    document.querySelectorAll('.review-btn').forEach(button => {
        button.addEventListener('click', function() {
            document.getElementById('reviewModal').style.display = 'block';
        });
    });

    document.querySelector('.close').addEventListener('click', function() {
        document.getElementById('reviewModal').style.display = 'none';
    });

    window.onclick = function(event) {
        if (event.target == document.getElementById('reviewModal')) {
            document.getElementById('reviewModal').style.display = 'none';
        }
    };

    document.getElementById('submitReview').addEventListener('click', function() {
        const content = document.getElementById('reviewContent').value;
        const orderId = document.querySelector('.review-btn').getAttribute('data-order-id');
        fetch('/untitled_war_exploded/addMark', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            body: `content=${encodeURIComponent(content)}&userId=${orderId}`
        })
            .then(response => response.json())
            .then(data => {
                if (data.success) {
                    alert('评价提交成功');
                } else {
                    alert('评价提交失败');
                }
                document.getElementById('reviewModal').style.display = 'none';
            });
    });
    </script>
</body>

</html>
